<?php

namespace Addons\OaSystem\Controller;
use Addons\OaSystem\Controller\OaDutyBaseController;

class OaEmpAdminLevelController extends OaDutyBaseController
{
    protected $model;

    function _initialize()
    {
        $this->model = $this->getModel('oa_emp_admin_level');
        parent::_initialize();

    }
    function lists(){
        $list_data = $this->_get_model_list( $this->model );
        $grids = $list_data['list_grids'];
        $data = $list_data['list_data'];

        array_multisort(array_column($data, 'level'), SORT_ASC, $data);
        $this -> assign('list_grids', $grids);
        $this->assign('list_data', $data);
        $this->display();
    }

    function add(){
        if(IS_POST) {
            $val['appid'] = $this->appId;
            $val['name'] = $_POST['name'];
            $val['level'] = $_POST['level'];

            if(db_find('oa_emp_admin_level', ['name'=>$val['name']])) {
                $this->error('该行政级别名称已经存在, 请重新输入！');
                return false;
            }

            M('oa_emp_admin_level')->add($val);

            $this->success ( '创建' . $model ['title'] . '成功！', U ( 'lists?model=' . $model ['name'], $this->get_param ));
        } else {
            $this->display('add');
        }
    }
}